<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head lang="en">
    <th:block th:include="include :: header('添加角色')"/>
</head>
<body>
<form class="layui-form" style="padding: 10px" lay-filter="form">
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">设备名称</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input type="text" id="name" name="name"-->
                   <!--class="layui-input" placeholder="请输入设备名称">-->
        <!--</div>-->
    <!--</div>-->
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">设备类型</label>-->
<!--        <div class="layui-input-block">-->
<!--            <select name="code" id="code">-->

<!--            </select>-->
<!--        </div>-->
<!--    </div>-->

    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">设备编码</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input type="text" id="code" name="code"-->
                   <!--class="layui-input" placeholder="请输入设备编码">-->
        <!--</div>-->
    <!--</div>-->

    <div class="layui-form-item">
        <label class="layui-form-label">设备编号</label>
        <div class="layui-input-block">
            <input type="text" id="number" name="number"
                   class="layui-input" placeholder="请输入设备编号">
        </div>
    </div>

    <input type="hidden" id="id" name="id">
    </div>
    <div style="display: none">
        <button class="layui-btn" lay-submit lay-filter="*" id="submit">立即提交</button>
    </div>
</form>
</body>
<th:block th:include="include :: footer"/>
<script type="text/javascript">

    var form;
    //从父层获取值，json是父层的全局js变量。eval是将该string类型的json串变为标准的json串
    layui.use(['form'], function () {
        form = layui.form;
        config.commGet("/ht/deviceListSimple.json",function (data) {
            var html="";
            for (var i=0;i<data.length;i++){
                html+=' <option value="'+data[i].code+'">'+data[i].className+'</option>'
            }
            $("#code").html(html);
            console.log(html)
            form.render()
        })
        if (parent.json) {
            var parent_json = parent.json;
            form.val("form", {
                "id": parent_json.id
               // , "name": parent_json.name
               //  , "code": parent_json.code
                , "number": parent_json.number
            })
        }
        form.render("select");                                // 刷性select，显示出数据
        form.on('submit(*)', function (data) {
            config.commPost("/ht/equipmentAdd.json", data.field, function (data, info) {
                parent.config.tableRefresh();
                parent.config.closeLayer(info);
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    })

    function ApplicationSave() {
        document.getElementById("submit").click();
    }
</script>
</html>

